package com.qd.panda.stroke;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.panda.domain.entity.order.OrderStatisticsDTO;
import com.qd.common.panda.domain.entity.stroke.preferential.UserStrokeOrderPreferentialLogDTO;
import com.qd.common.panda.domain.entity.stroke.preferential.UserStrokeOrderPreferentialLogDisplayDTO;
import com.qd.common.panda.domain.entity.stroke.preferential.UserStrokeOrderPreferentialLogQueryDTO;
import com.qd.panda.service.stroke.order.UserStrokeOrderPreferentialLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * WEB_用户订单优惠记录
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/sys/userOrderPreferentialLog/")
@Slf4j
public class UserOrderPreferentialLogController {
    private final UserStrokeOrderPreferentialLogService userStrokeOrderPreferentialLogService;

    /**
     * 优惠记录列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @PreAuthorize("@ps.hasPermission('system:userOrderPreferentialLog:pageOrderPreferentialLogDisplay')")
    @GetMapping(value = "pageOrderPreferentialLogDisplay")
    public IPage<UserStrokeOrderPreferentialLogDisplayDTO> pageOrderPreferentialLogDisplay(UserStrokeOrderPreferentialLogQueryDTO dto) {
        return userStrokeOrderPreferentialLogService.pageOrderPreferentialLogDisplay(PageUtil.buildPage(dto), dto);
    }

    /**
     * 优惠记录详情
     *
     * @param logId 日志ID
     * @return 优惠记录详情
     */
    @PreAuthorize("@ps.hasPermission('system:userOrderPreferentialLog:getOrderPreferentialLogByLogId')")
    @GetMapping(value = "getOrderPreferentialLogByLogId")
    public UserStrokeOrderPreferentialLogDisplayDTO getOrderPreferentialLogByLogId(@Validated @NotBlank(message = "日志ID不能为空") String logId) {
        return userStrokeOrderPreferentialLogService.getOrderPreferentialLogByLogId(logId);
    }

    /**
     * 优惠记录导出
     *
     * @param dto 查询参数
     */
    @PreAuthorize("@ps.hasPermission('system:userOrderPreferentialLog:export')")
    @GetMapping(value = "export")
    public void exportUserOrder(UserStrokeOrderPreferentialLogQueryDTO dto) {
        userStrokeOrderPreferentialLogService.export(dto);
    }

    /**
     * 根据订单ID查询优惠列表
     *
     * @param orderId 订单ID
     * @return 列表信息
     */
    @PreAuthorize("@ps.hasPermission('system:userOrderPreferentialLog:getOrderPreferentialByOrderId')")
    @GetMapping(value = "getOrderPreferentialByOrderId")
    public List<UserStrokeOrderPreferentialLogDTO> getOrderPreferentialByOrderId(@Validated @NotBlank(message = "订单ID不能为空") String orderId, Integer flag) {
        return userStrokeOrderPreferentialLogService.getCategoryListByOrderId(orderId,flag);
    }

    /**
     * 优惠记录统计
     *
     * @param dto 查询参数
     * @return 统计信息
     */
    @PreAuthorize("@ps.hasPermission('system:userOrderPreferentialLog:pageOrderPreferentialLogDisplay')")
    @GetMapping(value = "totalOrderStatistics")
    public OrderStatisticsDTO totalOrderStatistics(UserStrokeOrderPreferentialLogQueryDTO dto) {
        return userStrokeOrderPreferentialLogService.totalOrderStatistics(dto);
    }
}